<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <p>{{ msg }}</p>
        <p>{{ msg2 }}</p>
        <p>{{ user.age }}</p>

        <hr>
        <button @click="msg='today is monday'">修改msg</button>
        <button @click="user.age=25">修改user.age</button>
    </div>

    <script src="js/vue.js"></script>
    <script>
         new Vue({
            el: '#app',
            data: { // 普通属性
                msg: 'welcome to vue hello',
                user: {
                    id: 1001,
                    name: 'tangxiaoyang',
                    age: 18
                }
            },
            computed: { // 计算属性
                // 基于普通属性，进行处理，返回新的值
                msg2: function(){
                    return this.msg.toUpperCase().split(' ').reverse().join(' ')
                }
            },
            watch:{
                msg: function(newValue, oldValue){
                    console.log(newValue, oldValue)
                },
                user: {
                    handler: function(newValue){
                        console.log(newValue)
                    },
                    deep: true // 开启深度监听
                }
            }
         })
    </script>
</body>
</html>